package com.itheima.day05_多态和内部类.develophomework02.homework02;

public class Test {
    /*
    编写一个Animal类，具有属性：种类；具有功能：吃、睡。
    定义其子类Fish和Dog，
    定义接口LookHome,LookHome中编写抽象方法lookHome()让实现类实现，
    定义主类Test，在其main方法中分别创建其对象并测试对象的特性。
     */
    public static void main(String[] args) {
        Animal a = new Dog("金毛");
        Dog d = (Dog) a;
        a.eat();
        d.lookHome();
        Fish f = new Fish("鲨鱼");
        f.eat();
        f.sleep();

    }
}

abstract class Animal {
    private String kind;

    public abstract void eat();

    public abstract void sleep();

    public Animal() {
    }

    public Animal(String kind) {
        this.kind = kind;
    }

    public String getKind() {
        return kind;
    }

    public void setKind(String kind) {
        this.kind = kind;
    }
}

class Dog extends Animal implements LookHome {

    public Dog() {
    }

    public Dog(String kind) {
        super(kind);
    }

    @Override
    public void eat() {
        System.out.println("狗吃骨头");
    }

    @Override
    public void sleep() {
        System.out.println("狗在狗窝里睡觉");
    }

    @Override
    public void lookHome() {
        System.out.println("狗会看家");
    }
}

class Fish extends Animal {

    public Fish() {
    }

    public Fish(String kind) {
        super(kind);
    }

    @Override
    public void eat() {
        System.out.println("大鱼吃小鱼");
    }

    @Override
    public void sleep() {
        System.out.println("鱼在水里睡觉");
    }
}

interface LookHome {
    void lookHome();
}
